﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.Common;
using System.Linq.Expressions;

namespace Neotic.DataAccess.Sql.Operations
{
    public abstract class LogicalOperator : ISqlCondition
    {
        private ISqlCondition _leftCdt;
        private ISqlCondition _rightCdt;

        protected LogicalOperator() { }

        public LogicalOperator(ISqlCondition c1, ISqlCondition c2)
        {
            if (c1 == null)
                throw new ArgumentNullException("Paramètre c1 attendu");

            if (c2 == null)
                throw new ArgumentNullException("Paramètre c2 attendu");

            _leftCdt = c1;
            _rightCdt = c2;
        }

        public abstract string Operator { get; }

        public abstract ExpressionType? MyExpressionType { get; }

        public string ToSql(DbParameterCollection cmdParams)
        {
            return string.Concat("(", _leftCdt.ToSql(cmdParams), " ", this.Operator, " ", _rightCdt.ToSql(cmdParams), ")");
        }

        public ISqlCondition ParseExpression(Expression<Func<ISqlCondition, object>> predicate)
        {
            throw new NotImplementedException();
        }
        
    }
}
